﻿#region File Description
//  XAEnima 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  File description: Class used to store some utilities.
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XAEnima.Core.Comunication;
#endregion

namespace bci2.utils
{
    public class utils
    {
        public enum direction { up, down, left, right, none };

        public static byte[] BCIMessageToByte(BCIMessage.BCIMes str)
        {
            //System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            //return encoding.GetBytes(str);

            int k = 0;
            byte[] sendb = new byte[76];

            sendb[k++] = (byte)str.Kind;
            sendb[k++] = (byte)(str.Kind >> 8);
            sendb[k++] = (byte)(str.Kind >> 16);
            sendb[k++] = (byte)(str.Kind >> 24);

            sendb[k++] = (byte)str.Value;
            sendb[k++] = (byte)(str.Value >> 8);
            sendb[k++] = (byte)(str.Value >> 16);
            sendb[k++] = (byte)(str.Value >> 24);

            foreach (int i in str.Buffer)
            {
                sendb[k++] = (byte)i;
                sendb[k++] = (byte)(i >> 8);
                sendb[k++] = (byte)(i >> 16);
                sendb[k++] = (byte)(i >> 24);
            }

            sendb[k++] = (byte)str.Check;
            sendb[k++] = (byte)(str.Check >> 8);
            sendb[k++] = (byte)(str.Check >> 16);
            sendb[k++] = (byte)(str.Check >> 24);
            return sendb;
        }


        public static byte[] LEDCommandToByte(XAEnima.Core.Stimulation.External.LEDDriver.LED_Command str)
        {
            //System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            //return encoding.GetBytes(str);

            int k = 0;
            byte[] sendb = new byte[76];

            sendb[k++] = (byte)str.command;
            sendb[k++] = (byte)(str.command >> 8);
            sendb[k++] = (byte)(str.command >> 16);
            sendb[k++] = (byte)(str.command >> 24);

            foreach (int i in str.Data)
            {
                sendb[k++] = (byte)i;
                sendb[k++] = (byte)(i >> 8);
            }
            return sendb;
        }
    }
}
